package com.shbaiche.bifenba.adapter.data;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.shbaiche.bifenba.R;
import com.shbaiche.bifenba.model.GankResults;
import com.shbaiche.bifenba.model.data.TeamRankVo;
import com.shbaiche.bifenba.ui.data.DataTeamDetailActivity;
import com.shbaiche.bifenba.util.ToastUtil;
import com.shbaiche.bifenba.view.CircularImage;

import butterknife.BindView;
import cn.droidlover.xdroid.base.SimpleRecAdapter;
import cn.droidlover.xdroid.kit.KnifeKit;
import cn.droidlover.xdroidbase.imageloader.ILFactory;
import cn.droidlover.xdroidbase.router.Router;

/**
 * Created by wanglei on 2016/12/10.
 */

public class DataTeamListAdapter extends SimpleRecAdapter<TeamRankVo, DataTeamListAdapter.ViewHolder> {
    private Context mContext;

    public DataTeamListAdapter(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public ViewHolder newViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public int getLayoutId() {
        return R.layout.adapter_data_team_list;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        TeamRankVo item = data.get(position);

        ILFactory.getLoader().loadNet(holder.ivLogo, item.getLogo(), null);
        holder.tvName.setText(item.getTeamName());
        holder.tvValue.setText(item.getValue());

        holder.tvRank.setText(""+item.getRank());

        if(item.getRank() > 3){
            holder.tvRank.setTextColor(Color.BLACK);
        }else{
            holder.tvRank.setTextColor(Color.RED);
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getRecItemClick() != null) {
                    TeamRankVo item = data.get(position);

                    Intent intent = new Intent(mContext,DataTeamDetailActivity.class);
                    intent.putExtra(DataTeamDetailActivity.KEY_GAMETYPE,item.getGameType());
                    intent.putExtra(DataTeamDetailActivity.KEY_TEAMID,item.getTeamId());
                    mContext.startActivity(intent);
                }
            }
        });
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_logo)
        CircularImage ivLogo;

        @BindView(R.id.tv_rank)
        TextView tvRank;

        @BindView(R.id.tv_name)
        TextView tvName;

        @BindView(R.id.tv_value)
        TextView tvValue;





        public ViewHolder(View itemView) {
            super(itemView);
            KnifeKit.bind(this, itemView);
        }
    }
}
